package com.engineering.elink.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.DefaultValue;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.engineering.elink.common.ErrorType;
import com.engineering.elink.service.LabelService;
import com.engineering.elink.util.ResJsonUtil;

@RestController
@CrossOrigin
@RequestMapping("/api/label")
@Api(value="标签接口")
public class LabelController {
	
	@Autowired
	private LabelService labelService;

	/**
	 * 增加标签
	 */
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@ApiOperation(value="增加标签")
	public Map<String, Object> add(@ApiParam(value="标签集合,用,进行分割",required=true) @RequestParam("labels")String labels,
			@ApiParam(value="标签类型(0视频1技能)",required=true) @RequestParam("type")Integer type,HttpServletRequest request){
		@SuppressWarnings("unchecked")
		Map<String,Object> userInfo  = (Map<String, Object>) request.getAttribute("userInfo");
		String userId =  userInfo.get("userId").toString();
		
		return ResJsonUtil.getMap(ErrorType.SUCCESS,labelService.add(labels,userId,type));
		
	}
	
	@RequestMapping(value="/getLabel",method=RequestMethod.POST)
	@ApiOperation(value="获取标签")
	public Map<String, Object> getLabel(@ApiParam(value="类型(1资料2论文3课程4技能5问答6资迅)",required=true) @RequestParam("type")Integer type,
			@ApiParam(value="条数",required=false,defaultValue="2")@RequestParam("count")@DefaultValue("2") Integer count){
		return labelService.getLabel(type,count);
		
	}
	
	@RequestMapping(value="/getKeyLabel",method=RequestMethod.POST)
	@ApiOperation(value="获取关键字标签")
	public Map<String, Object> getKeyLabel(@ApiParam(value="类型(1资料2论文3课程4技能5问答6资迅)",required=true) @RequestParam("type")Integer type,
			@ApiParam(value="搜索内容",required=false) @RequestParam(value="keyWord",required=false)String keyWord,
			@ApiParam(value="条数",required=false,defaultValue="5")@RequestParam("count")@DefaultValue("5") Integer count){
		
		return labelService.getKeyLabel(type,keyWord,count);
		
	}
}
